package day13.CollectionTask;

import java.sql.SQLOutput;
import java.util.*;

public class LotterySoftware {
    public static void main(String[] args) {
        List<People> list = new ArrayList<>();
        Map<Integer, String> prize = new HashMap<>();
        prize.put(1, "一等奖");
        prize.put(2, "二等奖");
        prize.put(3, "二等奖");
        prize.put(4, "二等奖");
        prize.put(5, "三等奖");
        prize.put(6, "三等奖");
        prize.put(7, "三等奖");
        prize.put(8, "三等奖");
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入抽奖人姓名，多个抽奖人用\"|\"号分割：");
        String input = sc.nextLine();
        String[] names = input.split("\\|");
        System.out.println(list);
        System.out.println("确认开始抽奖吗？(YES OR NO): ");
        String confirm = sc.next();
        List<String> list1 = new ArrayList<>();//中奖信息
        boolean flag;
        int i1 = 0;
        Random r = new Random();
        List<Integer> list2 = new ArrayList<>();
        if (confirm.equalsIgnoreCase("YES")) {
            for (String name : names) {
                int i = name.hashCode();
                list.add(new People(i, name));
                flag = false;
                while (!flag) {
                    i1 = r.nextInt(3) + 1;
                    if (list2.contains(i1)) {
                        continue;
                    } else {
                        list2.add(i1);
                        flag = true;
                    }
                }
                System.out.println(i1);
                if (prize.get(i1) != null) {
                    String str = "中奖人：" + name + ",ID：" + i + "，奖品：" + prize.get(i1);
                    System.out.println(str);
                    list1.add(str);
                    prize.remove(i1);
                } else {
                    System.out.println("啥也没抽到");
                }
                System.out.print("输入next开始下一轮抽奖，输入其他任意键结束抽奖：");
                String next = sc.next();
                if (!next.equalsIgnoreCase("next")) {
                    for (String s : list1) {
                        System.out.println(s);
                    }
                    break;
                }
                if (prize.size() < 1) {
                    System.out.println("奖品已抽完，中奖汇总：");
                    for (String s : list1) {
                        System.out.println(s);
                    }
                    break;
                }
            }
        } else {
            System.out.println("没有开始抽奖");
        }
    }

}

class People {
    private Integer id;
    private String name;

    public People(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "People{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
